import './assets/tailwind.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/reset.css'
import App from './App.vue'
import router from './router'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { FastCrud } from '@fast-crud/fast-crud'
import '@fast-crud/fast-crud/dist/style.css'
import ui from '@fast-crud/ui-antdv4'
import '@fast-crud/ui-antdv4/dist/style.css'
import http from '@/http'

const app = createApp(App)

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
app.use(Antd)
app.use(ui)

app.use(FastCrud, {
  // 此处配置公共的dictRequest（字典请求）
  async dictRequest({ dict }) {
    return await http.post(dict.url) //根据dict的url，异步返回一个字典数组
  },
  //公共crud配置
  commonOptions() {
    return {
      toolbar: {
        buttons: {
          search: { show: false },
          compact: { show: false },
          export: { show: false },
          columns: { show: false }
        }
      },
      request: {
        //接口请求配置
        //你项目后台接口大概率与fast-crud所需要的返回结构不一致，所以需要配置此项
        //请参考文档http://fast-crud.docmirror.cn/api/crud-options/request.html
        transformQuery: ({ page, form = {}, sort }) => {
          //转换为你pageRequest所需要的请求参数结构
          return {
            index: page.currentPage - 1,
            size: page.pageSize,
            ...form
          }
        },
        transformRes: ({ res }) => {
          //将pageRequest的返回数据，转换为fast-crud所需要的格式
          //return {records,currentPage,pageSize,total};
          return {
            ...res,
            records: res.data,
            total: res.count
          }
        }
      }
    }
  }
})
app.use(pinia)
app.use(router)
app.mount('#app')
